package com.wkm.chainchain.blockchain.block;

import lombok.Data;
import lombok.ToString;

@Data
@ToString
public class Unit implements Comparable<Unit> {
    // 文件保存的路径及名字
    private String fileAddr;
    // 文件内容的哈希值
    private String fileHash;

    @Override
    public int compareTo(Unit obj) {
        return fileHash.compareTo(obj.getFileHash());
    }

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof Unit)) {
            return false;
        }
        if (this == obj) {
            return true;
        } else {
            Unit unitObj = (Unit) obj;
            return (this.fileAddr.equals(unitObj.getFileAddr()) && (this.fileHash.equals(unitObj.getFileHash())));
        }
    }

    @Override
    public int hashCode() {
        int hashNum = 20;
        hashNum = 23 * hashNum + 3 * (fileAddr == null ? 0 : fileAddr.hashCode())
                + 8 * (fileHash == null ? 0 : fileHash.hashCode());
        return hashNum;
    }
}
